package apis

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"gitee.com/kobeyyf/local_service/handler"
)

type HttpNothing struct {
}

func (api *HttpNothing) Helper() string {
	return "仅仅接收消息, 不会响应任何内容.将收到数据打印在终端."
}

func (api *HttpNothing) HandlerFunc(c *handler.Context) *handler.Respone {

	fmt.Println("====================================")
	fmt.Printf("发送到%s的%s请求\n", c.R.Host, c.R.Method)

	fmt.Println("头部:")
	fmt.Println(c.R.Header)

	fmt.Println("请求参数:")
	fmt.Println(c.R.RequestURI)
	if c.R.Method == http.MethodPost {
		fmt.Println("请求体内容")
		buf, err := ioutil.ReadAll(c.R.Body)
		if err != nil {
			fmt.Println("读取请求body 失败")
			fmt.Println(err)
		} else {
			fmt.Println(string(buf))
		}
	}

	fmt.Println("====================================\n")
	return nil
}
